package cn.itsource.mapper;

import cn.hutool.core.util.StrUtil;
import cn.itsource.basic.util.PageList;
import cn.itsource.domain.org.Employee;
import cn.itsource.vo.EmplQuery;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;

import java.util.List;
import java.util.Objects;


public interface EmployeeMapper extends BaseMapper<Employee> {



    default PageList<Employee> findPage(EmplQuery baseQuery){
        Page<Employee> page = new Page<>(baseQuery.getPage(),baseQuery.getPageSize());
        EntityWrapper<Employee> wrapper = new EntityWrapper<>();
        //如果店铺id不为空
        if (Objects.nonNull(baseQuery.getShopId()))
            wrapper.eq("shop_id", baseQuery.getShopId());
        //如果关键字不为空
        if (StrUtil.isNotBlank(baseQuery.getKeyword()))
        wrapper.eq("username", baseQuery.getKeyword());

        List<Employee> employees = this.selectPage(page, wrapper);
        return new PageList<>(page.getTotal(),employees);
    }
}
